#include "ntlauncher.h"
#include <QtWidgets/QApplication>
#include "singleapp.h"
#include "custombox.h"
#include "funcmgr.h"
#include <QTranslator>
#include <QtPlugin>
//Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

//回调函数
LONG ApplicationCrashHandler(EXCEPTION_POINTERS *Exception)
{
    sFunc->MBoxShow(QStringLiteral("程序出现错误 请联系管理员"));
    ::TerminateProcess(GetCurrentProcess(), 4);
    return EXCEPTION_EXECUTE_HANDLER;
}

int main(int Argc, char *Argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    SingleApplication App(Argc, Argv);

#ifdef __linux__
    sFunc->MBoxShow(QStringLiteral("登陆器只能Windows XP或以上系统运行!"));
    return 0;
#endif

    bool InClientDir = (sFunc->FolderIsExist(DirAppPath + "\\Data") && sFunc->FileIsExist(DirAppPath + "\\" + WowDName));
    if (!InClientDir)
    {
        sFunc->MBoxShow(QStringLiteral("登录器只能在Wow客户端目录下运行"));
        return 0;
    }

    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)ApplicationCrashHandler);

    QTranslator Translator;
    Translator.load(":/Resources/qt_zh_CN.qm");
    App.installTranslator(&Translator);

    Translator.load(":/Resources/widgets.qm");
    App.installTranslator(&Translator);

    if (!App.IsRun())
    {
        NtLauncher Launcher;
        App.MainWindow = &Launcher;
        Launcher.show();
        return App.exec();
    }
    return 0;
}
